package cn.tedu.boot21.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Controller
public class HelloController {
    //http://localhost:8080/hello
    //当客户端向地址发送请求是下面的hello方法会执行
    @RequestMapping("/hello")
    public void hello(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //获取客户端传递过来的参数
        String info = request.getParameter("info");


        System.out.println("收到请求了");
        //设置相应类型 告诉客户端相应的内容为什么类型
        response.setContentType("text/html; charset=utf-8");
        //得到输出对象 异常抛出
        PrintWriter pw=response.getWriter();
        //输出数据
        pw.println("<h1>恭喜你!测试成功</h1>"+info);
        //关闭资源
        pw.close();
    }

}



